package com.yixun.qfbao.util;

import org.apache.commons.lang.StringUtils;

public class ParseUtils {
    public static Float toFloat(String s){
        try{
            if(s == null){
                return null;
            }
            return Float.parseFloat(s);
        }catch (NumberFormatException e){
            return null;
        }
    }

    public static Integer toInteger(String s){
        try{
            return Integer.parseInt(s);
        }catch (NumberFormatException e){
            return null;
        }
    }

    public static Long toLong(String s){
        try{
            return Long.parseLong(s);
        }catch (NumberFormatException e){
            return null;
        }
    }

    /**
     * V10推送楼盘计算
     * @param s
     * @return
     */
    public static Float toFloat(String[] s){
        if(s == null){
            return null;
        }
        if(s.length > 1){
            Float start = StringUtils.isNotBlank(s[0])?toFloat(s[0]):0l;
            Float end = StringUtils.isNotBlank(s[1])?toFloat(s[1]):0l;
            if(start == 0l || end == 0l){
                return start + end;
            }
            return (start + end)/2l;
        }else if(s.length > 0){
            return toFloat(s[0]);
        }

        return new Float(0l);
    }
}
